﻿using MediatR;
using Traceability.APP.Application.Command.Health;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Health
{
    /// <summary>
    /// 保健信息的显示
    /// </summary>
    public class ShowAllCommandHandle:IRequestHandler<ShowAllCommand,APIResult<List<Health_Model>>>
    {
        private readonly IBaseRepository<Health_Model> HealthDal;

        public ShowAllCommandHandle(IBaseRepository<Health_Model> healthDal)
        {
            HealthDal = healthDal;
        }

        //public Task<APIResult<Health_Model>> Handle(ShowAllCommand request, CancellationToken cancellationToken)
        //{
        //    APIResult<Health_Model> result = new APIResult<Health_Model>();
        //    var list = HealthDal.GetAll().Where(x=>x.Batch == request.Batch).FirstOrDefault();
        //    result.Code = StateCode.Ok;
        //    result.Message = StateCode.Ok.ToString();
        //    result.Data = list;
        //    return Task.FromResult(result);
        //}

        Task<APIResult<List<Health_Model>>> IRequestHandler<ShowAllCommand, APIResult<List<Health_Model>>>.Handle(ShowAllCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Health_Model>> result = new APIResult<List<Health_Model>>();
            var list = HealthDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false).ToList();
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
